package de.koller.aframe.util.math.interpolation;

import de.koller.aframe.util.math.Function2DPreview;
import de.koller.aframe.util.math.IFunction2D;
import de.koller.oceanFramework.math.Interpolation;

public class AInterpolation3D {
	
	public static float interpolate( float x, float y, float... v ) {
		
		float t00x = AInterpolation.interpolateDerivate( v[ 4], v[ 5], v[ 6], v[ 7], 0 );
		float t10x = AInterpolation.interpolateDerivate( v[ 4], v[ 5], v[ 6], v[ 7], 1 );
		float t01x = AInterpolation.interpolateDerivate( v[ 8], v[ 9], v[10], v[11], 0 );
		float t11x = AInterpolation.interpolateDerivate( v[ 8], v[ 9], v[10], v[11], 1 );
		
		float t00y = AInterpolation.interpolateDerivate( v[ 1], v[ 5], v[ 9], v[13], 0 );
		float t01y = AInterpolation.interpolateDerivate( v[ 1], v[ 5], v[ 9], v[13], 1 );
		float t10y = AInterpolation.interpolateDerivate( v[ 2], v[ 6], v[10], v[14], 0 );
		float t11y = AInterpolation.interpolateDerivate( v[ 2], v[ 6], v[10], v[14], 1 );
		
		Interpolation.ISplineFunction2D s = Interpolation.interpolateFunc2D( 
				v[ 5], v[ 6], v[10], v[ 9],
				t00x, t00y, t10x, t10y,
				t11x, t11y, t01x, t01y );
		
		return s.f( x, y );
	}
	
	public static void main( String[] args ) {
		TestFunction t = new TestFunction();
		Function2DPreview.showFunction( 0, 0, 1, 1, t );
		//t.getValue( .2f, .3f );
	}
	
	private static class TestFunction implements IFunction2D {

		@Override
		public float getValue( float x, float y ) {
			return AInterpolation3D.interpolate( x, y,
				1, 1, 1, 1,
				1, 0, 0, 1,
				1, 0, 0, 1,
				1, 1, 1, 1 );
		}
		
	}
	
}
